Skip to content

Lab06#8

Open
pepegx wants to merge 29 commits intomasterfrom
lab06
Open

Lab06#8
pepegx wants to merge 29 commits intomasterfrom
lab06

Conversation

@pepegx
Copy link
Owner

@pepegx pepegx commented Mar 5, 2026

Lab 06: Advanced Ansible & CI/CD (Core + Bonus)

Summary

This PR delivers the full Lab 06 implementation (core tasks + bonus):

  • advanced role structure with block/rescue/always and tags,
  • Docker Compose migration for app deployment,
  • safe wipe flow,
  • split GitHub Actions pipelines for Python and Bonus apps,
  • multi-app deployment support with reusable role design.

Core Tasks Completed

  1. Blocks, rescue, always, tags
  • Refactored common and docker roles using block/rescue/always.
  • Added clear tag strategy (common, docker, docker_install, docker_config, etc.).
  • Verified selective execution and rescue behavior.
  1. Docker Compose migration
  • Replaced container-based deploy with community.docker.docker_compose_v2.
  • Added compose template rendering and deployment health checks.
  • Kept migration logic for legacy non-compose containers.
  1. Safe wipe logic
  • Added controlled wipe flow with dual guard:
  • web_app_wipe=true
  • --tags web_app_wipe
  • Wipe now also removes app container even if compose file was removed manually.
  1. CI/CD with GitHub Actions
  • Added and stabilized two workflows:
  • ansible-deploy.yml (Python app)
  • ansible-deploy-bonus.yml (Bonus app)
  • Added lint + deploy + verify jobs.
  • Deploy runs on self-hosted runner and validates endpoints after playbook run.
  • Added safer vault file cleanup in CI (trap ... EXIT).
  1. Documentation
  • Updated Lab 06 report with implementation details, validation, and workflow behavior.

Bonus Completed

  1. Multi-app deployment
  • Added app-specific vars and playbooks:
  • deploy_python.yml
  • deploy_bonus.yml
  • deploy_all.yml
  • Reused shared web_app role with per-app config.
  1. Multi-app CI
  • Separate triggers per app-specific file changes.
  • Shared role changes trigger both workflows.
  • Extended CI coverage to include:
  • playbooks/provision.yml
  • playbooks/deploy.yml
  • roles/common/**

Validation Performed

  • ansible-lint passed on expanded target set.
  • ansible-playbook --syntax-check passed for:
  • provision.yml
  • deploy.yml
  • deploy_python.yml
  • deploy_bonus.yml
  • deploy_all.yml
  • Local execution validated for core and bonus deploy/wipe scenarios.
  • GitHub Actions runs for both workflows completed successfully (lint + deploy).

Notes for Reviewer

  • deploy.yml default placeholders still require real image/credentials for real Docker Hub flow.
  • Local deterministic tests use local registry overrides (vars/local_test.yml, vars/local_multiapp_test.yml).

Checklist

  • Core Task 1 completed
  • Core Task 2 completed
  • Core Task 3 completed
  • Core Task 4 completed
  • Core Task 5 completed
  • Bonus Part 1 completed
  • Bonus Part 2 completed

pepega and others added 29 commits January 28, 2026 13:08
- Implement Flask-based DevOps Info Service (Python)
- Add GET / endpoint with service, system, runtime, and request info
- Add GET /health endpoint for monitoring
- Implement environment variable configuration (HOST, PORT, DEBUG)
- Add comprehensive documentation (README.md and LAB01.md)
- Include best practices: PEP 8, error handling, logging
- Add GitHub Community engagement section
- Implement bonus task: Go version of the service
- Add testing screenshots and evidence
- Pin dependencies in requirements.txt
- Configure .gitignore for Python and Go
- Add pytest unit tests (15 tests covering all endpoints)
- Add GitHub Actions workflow with matrix testing (Python 3.11, 3.12)
- Add ruff linter integration
- Add Docker build/push with CalVer versioning
- Add status badge to README
- Add LAB03.md documentation

Best practices:
- Dependency caching via setup-python
- Docker layer caching via Buildx
- Job dependencies (docker needs lint-test)
- Fail-fast matrix strategy
- Concurrency with cancel-in-progress
- Path filters for monorepo efficiency
- Docker build always runs (validates Dockerfile)
- Docker push only when DOCKERHUB secrets are configured
- Graceful handling when secrets not available
- Add .github/workflows/go-ci.yml for Go application
- Language-specific linting with golangci-lint
- Go testing with race detector and coverage
- Snyk security scanning for Go dependencies
- Docker build and push with CalVer versioning
- Path-based triggers for monorepo optimization
- Separate Docker image: pepegx/devops-info-service-go
- Parallel execution with Python CI workflow
…i-app support

Completes all main tasks (10pts) and bonus tasks (2.5pts):

MAIN TASKS (10pts):
- Unit Testing (3pts): pytest framework, 15 tests, 80% coverage
- GitHub Actions CI (4pts): python-ci.yml with matrix build, linting, testing, Docker push
- CI Best Practices (3pts): status badge, caching, Snyk security scanning

BONUS (2.5pts):
- Multi-App CI: go-ci.yml with path-based triggers
- Test Coverage: codecov integration with XML reporting

All requirements verified locally and ready for GitHub Actions execution.
- Fix codecov action file path (app_python/coverage.xml)
- Add CODECOV_TOKEN secret to codecov action
- Fix Snyk actions with proper file paths for both Python and Go
- Add Go CI status badge to app_go/README.md
- Fix codecov badge URL in app_python/README.md (remove token param)

All Lab03 requirements verified:
- 15 unit tests passing with 80% coverage
- Matrix builds for Python 3.11/3.12
- Snyk security scanning configured
- CalVer versioning implemented
- Path filters for monorepo
- Add main_test.go with 12 comprehensive unit tests
- Test all endpoints: /, /health, 404 handler
- Test helper functions: getEnv, getUptime, getSystemInfo
- Test custom mux wrapper with subtests
- Update README with unit testing documentation
- Update LAB03.md with test details

Coverage: 67.2% of statements
- Add pyproject.toml with 70% coverage threshold
- Configure pytest-cov fail-under for CI enforcement
- Add codecov upload for Go workflow
- Update LAB03.md with new coverage stats (98%)
- Simplify pytest command to use pyproject.toml config

Coverage improvements:
- Python: 98% coverage with 70% threshold
- Go: 67.2% coverage with codecov integration
- Refactor main.go: extract setupRouter() and printStartupBanner()
- Add TestSetupRouter to test router configuration
- Add TestPrintStartupBanner to test startup output
- Add TestDebugMode to test handlers with debug=true
- Coverage increased from 67.2% to 87.3% (above 70% threshold)
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
app_python/app.py 97.56% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants